package com.qinggeng.project.api.websocket.service;

import com.qinggeng.common.constant.HttpStatus;
import com.qinggeng.framework.config.mq.dto.MessageBulletChatDTO;
import com.qinggeng.framework.config.mq.dto.MessageLuckyDrawDTO;
import com.qinggeng.project.api.websocket.AppWebSocketServer;
import com.qinggeng.project.api.websocket.enums.MessageModelEnum;
import com.qinggeng.project.api.websocket.vo.MessageBulletChatVO;
import com.qinggeng.project.api.websocket.vo.MessageLuckyDrawVO;
import com.qinggeng.project.system.domain.SysUser;
import com.qinggeng.project.system.service.ISysUserService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 吴鹏飞
 * @date 2020/12/5
 */
@Component
public class BulletChatLuckyDrawServiceImpl {
    @Resource
    private ISysUserService userService;

    public  void  send( MessageLuckyDrawDTO dto){
        Long userId= dto.getUserId();
        if (null == userId){
            return;
        }
        SysUser sysUser=userService.selectUserById(userId);
        if (null !=sysUser){
            String nickName=sysUser.getNickName();
            MessageLuckyDrawVO messageModel=new MessageLuckyDrawVO();
            messageModel.setCode(HttpStatus.SUCCESS);
            messageModel.setType(MessageModelEnum.LUCKY_DRAW.getValue());
            messageModel.setUserId(String.valueOf(userId));
            Map<String,String> data= new HashMap<>();
            data.put("headImg",sysUser.getAvatar());
            StringBuilder stringBuilder=new StringBuilder();
            stringBuilder.append("恭喜")
                    .append(nickName)
                    .append("抽中了")
                    .append(dto.getGoodsName());
            data.put("context",stringBuilder.toString());
            messageModel.setData(data);
            AppWebSocketServer.massHair(messageModel);
        }
    }
}
